package pojo.bean;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;
import org.json.JSONPropertyName;

public class EmailUserPage {
    private EmailUser condition;
    private List<JSONObject> records;
    private int number;
    private int total;
    private int recordsCount;
    private int size;

    public EmailUserPage() {
        number = 1;
        size = 10;
        records = new ArrayList<>(size);
    }

    public EmailUserPage(int number, int rows) {
        this.number = number;
        this.size = rows;
        this.records = new ArrayList<>(size);
    }

    public EmailUser getCondition() {
        return condition;
    }

    public void setCondition(EmailUser condition) {
        this.condition = condition;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        if (number < 1) {
            this.number = 1;
        } else if (number > total) {
            this.number = total;
        } else {
            this.number = number;
        }
    }

    @JSONPropertyName("rows")
    public List<JSONObject> getRecords() {
        return records;
    }

    public void setRecords(List<JSONObject> records) {
        this.records = records;
    }

    @JSONPropertyName("total")
    public int getRecordsCount() {
        return recordsCount;
    }

    public void setRecordsCount(int recordsCount) {
        this.recordsCount = recordsCount;
        setTotal(recordsCount);
    }

    public int getSize() {
        return size;
    }

    @JSONPropertyName("pageTotal")
    public int getTotal() {
        return total;
    }

    public void setTotal(int recordsCount) {
        if (recordsCount > 0) {
            int quotient = recordsCount / size;
            this.total = recordsCount % size == 0 ? quotient : quotient + 1;
        } else {
            total = 1;
        }
    }

    @Override
    public String toString() {
        return "EmailUserPage [number=" + number + ", total=" + total + ", recordsCount=" + recordsCount + ", size="
            + size + "]";
    }
}
